package com.ais.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ais.dao.PersonDao;
import com.ais.vo.Deptment;
import com.ais.vo.Person;

import exception.LogicException;

@Service("personManage")
public class PersonManage {

	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
	}

	@Autowired
	private PersonDao personDao;

	public void addPerson(Person record) {
		this.personDao.insert(record);
	}
	
	public void updatePerson(Person record){
		this.personDao.updateByPrimaryKey(record);
	}
	
	public void deletePerson(Person record){
		this.personDao.deleteByPrimaryKey(record.getId());
	}

	public List<Person> listPerson(Person person) {
		return this.personDao.selectPersons(person);
	}

	public boolean login(String userName, String password) {
		if(StringUtils.isBlank(userName)||StringUtils.isBlank(password)){
			throw new LogicException("参数不正确");
		}
		if(!personDao.login(userName,password)){
			throw new LogicException("用户名或者密码错误");
		}else{
			return true;
		}
	}

}
